#!/user/bin/env node

const log = console.log,
      http = require('http');

http.createServer((req,res)=>{
  log(req.url);
  log(req.method);
  if(req.url !== '/'){
    err(res);
    return;
    //res.statusCode = 404;
    //res.end('Resource not found! 404');
  }
  if(req.method !== 'POST'){
    err(res);
    //res.end('not post, client err!');
  }else{
    req.pipe(process.stdout);
    res.end('ok!');
  }
}).listen(8080);

function err(res){
  let msg = 'not found!';
  res.statusCode = 404;
  res.setHeader('Content-Length',msg.length);
  res.setHeader('Content-Type','text/plain');
  res.end(msg);
}
